package com.oracle.interceptor;


import com.oracle.Service.impl.BookService;
import com.oracle.pojo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

public class UserInterceptor extends HandlerInterceptorAdapter {

    @Autowired
    private BookService bookService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //库存从低到搞的是本书
        List<Book> list = bookService.selectBooksByNumOrder();
        if (list!=null){
            request.setAttribute("MaxNumOnebook",list.get(0));
            request.setAttribute("MaxNumTwobook",list.get(1));
            request.setAttribute("MaxNumListbook", list.subList(2,list.size()));
        }
        return true;
    }
}
